class Counter{
    public int count = 0;
    public synchronized void display(){
        System.out.println("hhh");
    }
    public synchronized void add(){
        count++;
    }
}
public class TestDemo {
    public static void main(String[] args) {
        Counter counter = new Counter();
        Thread t1 = new Thread(()->{
                System.out.println("t1before");
                counter.add();
                System.out.println("t1after");

        });
        /*Thread t2 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                counter.add();
            }
        });*/
        Thread t2 = new Thread(()->{
                System.out.println("t2before");
                counter.add();
                System.out.println("t2after");

        });
        t1.start();
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(counter.count);

    }
}
